#include <iostream>
#include <QCoreApplication>
#include <QCommandLineParser>
#include <QDebug>
#include "OrgClientEvnCfg.h"

int main(int argc, char *argv[]) {
    QCoreApplication a(argc, argv);
    QCommandLineParser parser;      // 命令行解析器
    parser.addHelpOption();         // 设置帮助选项

    parser.addPositionalArgument(QObject::tr("[installDir]"),
                                 QObject::tr("安装目录"));
    parser.addPositionalArgument(QObject::tr("[dbCharset]"),
                                 QObject::tr("字符集."));
    QCommandLineOption installOption(QStringList() << "i" << "install", "安装数据库");
    parser.addOption(installOption);

    QCommandLineOption removeOption(QStringList() << "r" << "remove", "卸载数据库");
    parser.addOption(removeOption);


    parser.process(QCoreApplication::arguments());

    OrgClientEvnCfg orgClientEvnCfg;
    // 取参数
    int argSize = parser.positionalArguments().size();
    qDebug() << "Arguments size:" << argSize;
    QString installDir;
    QString charset;
    if (argSize == 1) {
        installDir = parser.positionalArguments().at(0);
        // 不指定字符集时候的默认值
        charset= "SIMPLIFIED CHINESE_CHINA.ZHS16GBK";
    }
    if (argSize == 2) {
        installDir = parser.positionalArguments().at(0);
        charset= parser.positionalArguments().at(1);
    }

    if (parser.isSet(removeOption)) {
        qDebug() << "removeOption";
        orgClientEvnCfg.onRemoveEnv();
    } else if (parser.isSet(installOption)) {
        qDebug() << "installOption";
        orgClientEvnCfg.onSaveEnv(installDir, charset);
    } else {
        // 未给参数,则默认进行安装
        qDebug() << "defaultOption";
        orgClientEvnCfg.onSaveEnv(installDir, charset);
    }

    return 0;

}